package com.bootdo.wx.service.impl;

import com.bootdo.common.utils.PageHelperUtils;
import com.bootdo.wx.dao.MemberExtractDao;
import com.bootdo.wx.dao.MemberPriceDao;
import com.bootdo.wx.domain.MemberPriceDO;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bootdo.wx.dao.OrderComDao;
import com.bootdo.wx.domain.OrderComDO;
import com.bootdo.wx.service.OrderComService;



@Service
public class OrderComServiceImpl implements OrderComService {
	@Autowired
	private OrderComDao orderComDao;
	@Autowired
	private MemberExtractDao memberExtractDao;
	@Autowired
	private MemberPriceDao memberPriceDao;
	
	@Override
	public OrderComDO get(String id){
		return orderComDao.get(id);
	}
	
	@Override
	public List<OrderComDO> list(Map<String, Object> map){
		return orderComDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return orderComDao.count(map);
	}
	
	@Override
	public int save(OrderComDO orderCom){
		return orderComDao.save(orderCom);
	}
	
	@Override
	public int update(OrderComDO orderCom){
		return orderComDao.update(orderCom);
	}
	
	@Override
	public int remove(String id){
		return orderComDao.remove(id);
	}
	
	@Override
	public int batchRemove(String[] ids){
		return orderComDao.batchRemove(ids);
	}

	@Override
	public Map<String,Object> getMemberCom(Map<String, Object> map) {
		//提现总金额
		map.put("type","0");
		BigDecimal xPrice =  memberPriceDao.getSPriceByUser(map);   //消费  -
		map.put("type","1");
		BigDecimal tPrice =  memberPriceDao.getSPriceByUser(map);   //提现  -
		map.put("type","2");
		BigDecimal cPrice =  memberPriceDao.getSPriceByUser(map);   //充值  +
		map.put("type","3");
		BigDecimal fPrice =  memberPriceDao.getSPriceByUser(map);   //返利  +

		BigDecimal sPrice =  fPrice;   //收益
		BigDecimal allPrice =  cPrice.add(fPrice).subtract(xPrice).subtract(tPrice);   //余额
		//可提现余额
		BigDecimal canExPrice = new BigDecimal(0);
		if (xPrice.compareTo(cPrice) == 1) {  //消费大于充值
			canExPrice = fPrice.subtract(tPrice).subtract(xPrice.subtract(cPrice));
		} else {
			canExPrice = fPrice.subtract(tPrice);
		}

		Map<String,Object> priceMap = new HashMap<>();
		priceMap.put("extractMoney",tPrice);
		priceMap.put("allPrice",allPrice);
		priceMap.put("sPrice",sPrice);
		priceMap.put("canExPrice",canExPrice);
		return priceMap;
	}

	@Override
	public PageInfo<MemberPriceDO> getMemberComList(Map<String, Object> paramMap) {
		paramMap.put("delFlag","0");
		PageHelperUtils.page(paramMap);
		List<MemberPriceDO> list = memberPriceDao.list(paramMap);
		PageInfo<MemberPriceDO> pageInfo = new PageInfo<>(list);
		return pageInfo;
	}

}
